package com.brotherly.util;

import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class XMLHelper
{
    public static NodeList selectNodes(XPath xpath, String expr, Object node) throws XPathExpressionException
    {
        NodeList nodes = (NodeList) xpath.evaluate(expr, node, XPathConstants.NODESET);

        return nodes;
    }

    public static Node selectSingleNode(XPath xpath, String expr, Object node) throws XPathExpressionException
    {
        Node result = (Node) xpath.evaluate(expr, node, XPathConstants.NODE);

        return result;
    }

    public static String selectString(XPath xpath, String expr, Object node) throws XPathExpressionException
    {
        String value = (String) xpath.evaluate(expr, node, XPathConstants.STRING);

        return value;
    }
}
